<?php

class ChangeForm extends CFormModel
{
	public $password;
	public $password_new;
	public $password_new_repeat;
	public $id;

	public function rules()
	{
		return array(
			array('password, password_new, password_new_repeat', 'required'),
			array('password_new', 'compare'),
			array('password_new', 'length', 'min'=>8, 'max'=>100),
			array('password_new_repeat', 'length', 'min'=>8, 'max'=>100),
			array('password', 'verify'),
			
		);
	}
	public function verify($attribute, $params)
	{    
		$model =usuarios::model()->findByPk(Yii::app()->user->id);
		if($model->password!=md5($this->password))
		{
			$this->addError('password', 'Contraseña incorrecta');
		}
	}


	public function attributeLabels()
	{
		return array(
			'password'=>'Contraseña actual',
			'password_new'=>'Nueva contraseña',
			'password_new_repeat'=>'Confirmar contraseña',
		);
	}


}